<form action="index.php" method="post" name="adminForm" id="adminForm">
<script type="text/javascript">
jQuery(document).ready(
  function(){
    jQuery("#adminForm").validate({
      rules:  {
        schedule_id:{
          required: true,
        },
        second_team_final_score:{
          required: true,
          digits: true
        },
        first_team_final_score:{
          required: true,
          digits: true
        },
        game_end_status_id:{
          required: true
        }
      }
    });
  }
);
</script>
  <fieldset class="adminform">
    <legend>Details</legend>
      <?
        $id                  = 0;
        $schedule_id            = 0;
        $first_team_id            = 0;
        $second_team_id          = 0;
        $first_team_final_score  = 0;
        $second_team_final_score = 0;
        $game_end_status_id      = 0;
        $published               = true;
        
        if(isset($this->stat)){
          $id                  = $this->stat->id;
          $schedule_id            = $this->stat->schedule_id;
          $first_team_id            = $this->stat->first_team_id;
          $second_team_id          = $this->stat->second_team_id;
          $first_team_final_score  = $this->stat->first_team_final_score;
          $second_team_final_score = $this->stat->second_team_final_score;
          $game_end_status_id      = $this->stat->game_end_status_id;
          $published               = $this->stat->published;  
        }
        
        if(isset($this->teams)){
          $teams = $this->teams;
          $temp  = array();
          foreach($teams as $team)
            $temp[$team->id] = $team;
          $teams = $temp;
        }
          
        if(isset($this->schedules))
          $schedules = $this->schedules;
          
        if(isset($this->game_end_statuses))
          $game_end_statuses = $this->game_end_statuses;
        
      ?>
            <table class="admintable">
        <tr valign='top'>
          <td class="key">Teams</td>
          <td>
            <? $html_attrib = "size=20 onchange=\"ajx_request('". JRequest::getVar('c', 'gamestat') ."', 'ajx_select_scheds', 'team_id='+this.value , 'div_scheds');\""; ?>
            <?= JHTML::_('select.genericlist', $teams, 'team_id', $html_attrib, 'id', 'name', $first_team_id) ?>
          </td>
                    <td class="key">Schedule</td>
          <td>
            <div id="div_scheds">
            <? $html_attrib = "size=20 onchange=\"ajx_request('". JRequest::getVar('c', 'gamestat') ."', 'ajx_select_sched_details', 'schedule_id='+this.value , 'div_teams');\"";  ?>
            <?= JHTML::_('select.genericlist', $schedules, 'schedule_id', $html_attrib, 'id', 'schedule', $schedule_id) ?>
            </div>
          </td>
        </tr>
        <tr>
                    <td class="key">Final Scores</td>
          <td colspan="3">
            <div id="div_teams">
            <? if($id): ?>
              <?= JText::_($teams[$first_team_id]->name); ?>
              <input type="text" name="first_team_final_score" id="first_team_final_score" value="<?= $first_team_final_score ?>" />
              <?= JText::_(' VS. ') ?>
              <?= JText::_($teams[$second_team_id]->name); ?>
              <input type="text" name="second_team_final_score" id="second_team_final_score" value="<?= $second_team_final_score ?>" />
            <? endif ?>
            </div>
          </td>
        </tr>
        <tr>
                    <td class="key">Status</td>
          <td>
            <?= JHTML::_('select.genericlist', $game_end_statuses, 'game_end_status_id', 'size='.count($game_end_statuses), 'id', 'name', $game_end_status_id) ?>
          </td>
        </tr>
        <tr>
          <td class="key">Published</td>
          <td>
            <?= JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $published); ?>
          </td>
        </tr>
             </table>
       </fieldset>
       <input type="hidden" name="option" value="<?= JRequest::getVar( 'option' );?>"/>
     <input type="hidden" name="c" value="<?= JRequest::getVar('c', 'game_stat'); ?>" />
       <input type="hidden" name="id" value="<?= $id; ?>"/>
     <input type="hidden" name="task" value=""/>
</form>
